﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Web.UI.WebControls;

namespace CorreoSocialWeb.Views
{
    public class ErroresHelper
    {
        public const string DefaultSeparator = "</br>";
        public List<string> Items;

        public ErroresHelper()
        {
            this.Items = new List<string>();
        }

        public void Add(string error, Label label)
        {
            this.Add(error);

            label.Text = error;
        }

        public void Add(string error)
        {
            this.Items.Add(error);
        }

        public string Get(string separator = DefaultSeparator)
        {
            string s = string.Empty;

            foreach (string i in this.Items)
                s += String.Format("{0}{1}", i, separator);

            if (this.HayErrores)
                s = s.Substring(0, s.Length - separator.Length);

            return s;
        }

        public bool HayErrores
        {
            get
            {
                return this.Items.Any();
            }
        }
    }
}